#include<iostream>
#include<signal.h>
#include<unistd.h>



void PrintBlock()
{
    sigset_t set,oset;
    sigemptyset(&set);
    sigemptyset(&oset);

    sigprocmask(SIG_BLOCK,&set,&oset);
    std::cout << "block:" << std::endl;
    for(int signo = 31;signo > 0;signo--)
    {
        if(sigismember(&oset,signo))
        {
            std::cout << 1;
        }
        else
        {
            std::cout << 0;
        }
    }
    std::cout << std::endl;
}


void PrintPending()
{
    sigset_t pending;
    sigemptyset(&pending);

    std::cout << "pending:" << std::endl;
    for(int signo = 31;signo > 0;signo--)
    {
        if(sigismember(&pending,signo))
        {
            std::cout << 1;
        }
        else
        {
            std::cout << 0;
        }
    }
    std::cout << std::endl;
}


void handler(int signo)
{
    static int cnt = 0;
    cnt++;
    while(true)
    {
        std::cout << "get a signo" << signo << std::endl;
        PrintBlock();
        sleep(1);
        break;
    }
    //exit(1);
}


int main()
{
    struct sigaction act,oact;
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask,3);
    sigaddset(&act.sa_mask,4);
    sigaddset(&act.sa_mask,5);

    ::sigaction(2,&act,&oact);

    while(true)
    {
        PrintPending();
        pause();
    }

    return 0;
}